function init() {

	// center container
	ContainerCenter();
	$(window).resize(ContainerCenter);
	
	// center menu
	var menu_first_item = $("#menu li:first");
	var menu_width = $("#menu").width();
	var total_width = 0;
	$("#menu li").each(function(){total_width += $(this).width()})
	menu_first_item.animate({
		marginLeft: Math.round((menu_width-total_width-50)/2)
	}, 0);

	// dancers positions
	InitDancers();
	$(window).resize(InitDancers);
	
	// load dancers
	$.ajax({
		url: root + "/ajax/dancers",
		beforeSend: function() {
			$(".dancer").addClass("loading");
		},
		complete: function(req) {
			$(".dancer").removeClass("loading");
			if(req.status==200) {
				var dancers = eval("("+req.responseText+")");
				var dancerLeft = $("#dancer-left");
				var dancerRight = $("#dancer-right");
				var speed = 2000;
				
				dancerLeft.hide();
				dancerRight.hide();
				
				dancerLeft.find("img").attr("src", root + dancers[0]);
				dancerRight.find("img").attr("src", root + dancers[1]);
				
				dancerLeft.fadeIn(speed);
				dancerRight.fadeIn(speed);
			}
		}
	});
}
function ContainerCenter() {
	var container = $("#container");
	var container_position = container.position();
	if(container_position.left==0) {
		var l = Math.round(($(window).width() - $("#container").width())/2);
		l = l>0 ? l : 0;
		container.css("margin-left", l);
	}
}
function InitDancers() {
	var container = $("#container")
	var container_position = container.position();
	var left = container_position.left;
	left = left>0 ? left : parseInt(container.css("margin-left"));
	$(".dancer").css("left", left);
}

function ImageGalleryCenterImages() {
	var loaded = true;
	$(".gallery-list img").each(function(){
		var li = $(this).parent();
		var h = $(this).height();
		var h_li = li.height();
		if(h < h_li) {
			if(h>0) {
				$(this).css("marginTop", Math.round((h_li-h)/2));
			}else{
				loaded = false;
			}
		}
	});
	if(!loaded) {
		setTimeout(ImageGalleryCenterImages,500);
	}
}

function SendContact() {
	var sendStatus = $("#send-status");
	var submitButton = $("input.submit");
	var throbber = $('<img src="'+root+'/img/throbber.gif" />');
	$.ajax({
		url: root + "/contact/send",
		data: "data[name]=" + $("#name").val() + "&data[email]=" + $("#email").val() + "&data[message]=" + $("#message").val() + "&data[captcha]=" + $("#captcha").val(),
		beforeSend: function() {
			sendStatus.attr("class", "");
			submitButton.attr("disabled", true);
			sendStatus.html(throbber);
		},
		complete: function(req) {
			submitButton.attr("disabled", false);
			if(req.status == 200) {
				var status = parseInt(req.getResponseHeader("X-Contact-Status"));
				sendStatus.html(req.responseText);
				if(status) {
					sendStatus.attr("class", "error");
				}else{
					sendStatus.attr("class", "ok");
				}
			}else{
				sendStatus.attr("class", "error");
				sendStatus.html(req.statusText);
			}
		}
	});
}